import Vue from 'vue'
import VueRouter from 'vue-router'
import Film from '../views/Film.vue'
import Cenima from '../views/Cenima.vue'
import Center from '../views/Center.vue'
import CommingSoon from '../views/film/CommingSoon.vue'
import NowPlaying from '../views/film/NowPlaying.vue'
import Detail from '../views/Detail.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/film',
    component: Film,
    children: [
      {
        path: 'commingsoon',
        component: CommingSoon
      },
      {
        path: '/film/nowplaying',
        component: NowPlaying
      },
      {
        path: '',
        component: NowPlaying
      }
    ]
  },
  {
    path: '/cenima',
    component: Cenima
  },
  {
    path: '/login',
    component: () => import('../views/Login.vue')// 路由懒加载
  },
  {
    path: '/center',
    component: Center
  },
  // {
  //   path:'/detail/:myid',
  //   component:Detail,
  //   name:'detail'
  // },
  {
    path: '/detail',
    component: Detail
  },
  {
    path: '*',
    redirect: '/film'
  }
]

const router = new VueRouter({
  // mode: 'history',
  // base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (to.fullPath === '/center') {
    if (!localStorage.getItem('token')) {
      next('/login')
    } else {
      next()
    }
  } else {
    next()
  }
})

export default router
